package com.djpeng.du.simple_pinyin;

import java.io.*;

/**
 * Created by dujp on 15/5/3.
 * djpeng.du@gmail.com
 */
public class Convert {
    public static void main(String[] args) throws Exception{
        String name = "/unicode_to_hanyu_pinyin.txt";
        BufferedReader reader = new BufferedReader(new InputStreamReader(Convert.class.getResourceAsStream(name)));
        String line;
        StringBuilder builder = new StringBuilder();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("py.txt"))));
        while((line=reader.readLine())!=null){
            builder.delete(0, builder.length());
            String[] strs = line.split(" ");
            builder.append(strs[0]).append(" ").append("(");
            String value = strs[1].substring(1, strs[1].length() - 1);
            String[] vs = value.split(",");
            String last="";
            for(int i=0; i<vs.length; i++){
                String cur = vs[i].substring(0, vs[i].length()-1);
                if(last.equals(cur)){
                    continue;
                }
                if(i!=0){
                    builder.append(",");
                }
                builder.append((last=cur));
            }
            builder.append(")");
            writer.write(builder.toString());
            writer.newLine();
        }
        writer.flush();
        reader.close();
        writer.close();
    }
}
